<?php
defined('BASEPATH') or exit('No direct script access allowed');

class dept_data_service
{
    private $CI;
    public function __construct()
    {
        $this->CI = &get_instance();
        $this->CI->load->model("Academia_job_model");
        $this->CI->load->model("Academic_report_model");
        $this->CI->load->model("Audit_model");
        $this->CI->load->model("Awards_model");
        $this->CI->load->model("Communication_model");
        $this->CI->load->model("Horizontal_project_model");
        $this->CI->load->model("Monograph_model");
        $this->CI->load->model("Paper_model");
        $this->CI->load->model("Patent_data_model");
        $this->CI->load->model("Patent_model");
        $this->CI->load->model("Research_report_model");
        $this->CI->load->model("Science_conversion_model");
        $this->CI->load->model("Technical_standard_model");
        $this->CI->load->model("Vertical_project_model");
        $this->CI->load->model("Subject_platform_model");
        $this->CI->load->model("User_model");
        $this->CI->load->library('PHPExcel/PHPExcel');        
        $this->CI->load->model("Admin_model");
    }


    //论文模块
   
    public function paper($param, $is_export,$is_school,$check){
          if($is_export && !$is_school){
                 $connar['items'] = "db_paper.id,db_paper.publish_time,db_paper.name,db_paper.journal_name,db_paper.journal_level,db_paper.subject,db_paper.school_rank,db_paper.personal_rank,author.author,author.identity,db_paper.volume_number,db_paper.issue_number,db_paper.page_range,db_paper.words_number,db_paper.cn,db_paper.issn,db_paper.journal_type,db_paper.journal_range,db_paper.is_cooperation,db_paper.type,db_paper.dept_name,db_paper.performance_score,db_paper.bonus,db_paper.award_year";
            }else{
    
                 $connar['items'] = "db_paper.id,db_paper.publish_time,db_paper.name,db_paper.journal_name,db_paper.journal_level,db_paper.subject,db_paper.school_rank,db_paper.personal_rank,author.author,author.identity,db_paper.type,db_paper.award_year";
            }
           

            $connar['where'] = $this->CI->sqlEscape("is_del=?? and status=?? and is_submit_cg=??", array(CommonWhether::Not[XPHEnum::Value], ResultState::Publiced[XPHEnum::Value],CommonWhether::Whether[XPHEnum::Value]));
            $connar['join'][0]=array('(select group_concat(db_author.author_name  ORDER BY id ASC) author,group_concat(db_author.identity  ORDER BY id ASC) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::First[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_paper.id');
            if (isset($param['name']) && $param['name']!=-1) {
                $name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
                $connar['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::First[XPHEnum::Value].') author1','author1.data_id=db_paper.id');
                 $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));
            }

            if (isset($param['year']) && $param['year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and DATE_FORMAT(FROM_UNIXTIME(db_paper.publish_time), "%Y" ) =?? ', array($param['year']));
            }
            if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and db_paper.award_year=?? ', array($param['submit_year']));
            }
            if (isset($param['dept']) && $param['dept']!=-1) {
                if (strpos($param['dept'],'分院') !== false) {
                    $deptname = strstr($param['dept'], '分院', true);
                    $connar['where'] .= " and db_paper.dept_name like '%".$deptname."%'";
                }
                // else if($param['dept'] == '公共基础教学部'){
                //     $connar['where'] .= " and db_paper.dept_name like '%".$param['dept']."%'";
                // }
                else if($param['dept'] == '职能管理部'){
                    $dept_data = array();
                    foreach ((new addDept())->getAll() as $k => $v) {
                        if($v[XPHEnum::Alternate] > 100 && $v[XPHEnum::Alternate] < 200){
                            $dept_data[$k]= $v[XPHEnum::Caption];
                        }
                    }
                    $dept_data[count($dept_data)] = '职能管理部';
                   $deptnames = implode("','",$dept_data);
                   $connar['where'] .= " and db_paper.dept_name in ('".$deptnames."')";
   
                }else{
                    $connar['where'] .= $this->CI->sqlEscape(' and db_paper.dept_name=?? ', array($param['dept'])); 
                }
                // $connar['where'] .= $this->CI->sqlEscape(' and db_paper.dept_name=?? ', array($param['dept']));
            }  

            
            if($is_export && !$is_school){
                if(isset($check) && !empty($check)){
                    if(in_array(ResultsType::First[XPHEnum::Value], $check)){
                        $id_data=$param['check'][ResultsType::First[XPHEnum::Value]];
                        $id = '';
                        foreach ($id_data as $k => $v) {
                            if($k==0){
                                $id="'".$v."'";
                            }else{
                                $id.=",'".$v."'";
                            }
                        }
                        $connar['where'] .=" and db_paper.id in(".$id.")";
                    }else{
                        $connar['where'].=" and 1<>1";
                    }
                }else{
                    $connar['where'].=" and 1<>1";
                }
            }


            $data = $this->CI->Paper_model->get_list_full($connar);

            // echo $this ->CI-> db -> last_query();

            // pri($data);
       
            foreach ($data as $k => $v) {
                if(isset($v['is_cooperation'])){
                    $data[$k]['is_cooperation'] = (new CommonWhether())->show($v['is_cooperation']);
                }               
                $data[$k]['publish_time'] = $v['publish_time'] ? date('Y-m-d', $v['publish_time']) : '--';
                 if(isset($v['award_year'])){
                     $data[$k]['award_year'] = $v['award_year']?$v['award_year']:'';               
                }else{
                     $data[$k]['award_year'] = '';
                }
                if(isset($param['name']) && $param['name']!=-1){
                   
                    // 判断是否外校
                    $author=array_unique(explode(',', $v['author']));
                    $own_identity=array_search(CommonIdentity::Teacher[XPHEnum::Value], explode(',', $v['identity']));
                    $own_author=array_search($param['name'], explode(',', $v['author']));
                    // 如果该成果人不是排在成果人第一位，则排名都显示为成员
                      //  pri($author[$own_identity]);
                      $name_arr = explode(",",$param['name']);
                     $name = $name_arr[0];
                    if($name !=$author[0]){
                        $data[$k]['school_rank']='成员';
                        $data[$k]['personal_rank']='成员';
                    }
                }
                unset($data[$k]['identity']);  
            }

            if($is_export && !$is_school){
                $table_col = array('选择','序号', '发表时间', '论文题目', '刊物名称', '刊物级别', '学科门类', '本校排名', '个人排名','作者','卷号','期号','页码范围','字数(千字)','CN','ISSN','刊物发行类型','刊物发表范围','是否合作完成','论文类型','所属单位','业绩分','奖金','业绩（成果）归属年份');
            }else{
                  $table_col = array('选择','序号', '发表时间', '论文题目', '刊物名称', '刊物级别', '学科门类', '本校排名', '个人排名', '作者','论文类型','业绩（成果）归属年份');
            }
       
            $type_name         = ResultsType::First[XPHEnum::Caption];

            return  array('table_name' => $type_name, 'table_col' => $table_col, 'data' => $data);
            
    }

    //专著模块
   
    public function monograph($param, $is_export,$is_school,$check){
         if($is_export && !$is_school){
                 $connar['items'] = "db_monograph.id,db_monograph.publish_time,db_monograph.name,db_monograph.publish_house,db_monograph.publish_house_level,db_monograph.subject,db_monograph.school_rank,db_monograph.personal_rank,author.author,author.identity,db_monograph.words_number,db_monograph.school_words_number,db_monograph.type,db_monograph.nature,db_monograph.publish_address,db_monograph.isbn,db_monograph.is_cooperation,db_monograph.dept_name,db_monograph.performance_score,db_monograph.bonus,db_monograph.remark,db_monograph.award_year";

                  // $connar['items'] = "id,publish_time,name,publish_house,publish_house_level,subject,school_rank,author.author";
             }else{
                  $connar['items'] = "db_monograph.id,db_monograph.publish_time,db_monograph.name,db_monograph.publish_house,db_monograph.publish_house_level,db_monograph.subject,db_monograph.school_rank,db_monograph.personal_rank,author.author,author.identity,db_monograph.award_year";
             }
          

            $connar['where'] = $this->CI->sqlEscape("is_del=?? and status=?? and is_submit_cg=??", array(CommonWhether::Not[XPHEnum::Value], ResultState::Publiced[XPHEnum::Value],CommonWhether::Whether[XPHEnum::Value]));
            $connar['join'][0]=array('(select group_concat(db_author.author_name  ORDER BY id ASC) author,group_concat(db_author.identity  ORDER BY id ASC) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Second[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_monograph.id');

            // if (isset($param['name']) && $param['name']!=-1) { 
            //     $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author.author) ', array($param['name']));
            // }
            if (isset($param['name']) && $param['name']!=-1) {
                $name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
                $connar['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Second[XPHEnum::Value].') author1','author1.data_id=db_monograph.id');
                 $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));
            }

            if (isset($param['year']) && $param['year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and DATE_FORMAT(FROM_UNIXTIME(db_monograph.publish_time), "%Y" ) =?? ', array($param['year']));
            }
            if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and db_monograph.award_year=?? ', array($param['submit_year']));
            }
            if (isset($param['dept'])) {
                $connar['where'] .= $this->CI->sqlEscape(' and db_monograph.dept_name=?? ', array($param['dept']));
            }
            if($is_export && !$is_school){
                if(isset($check) && !empty($check)){
                      if(in_array(ResultsType::Second[XPHEnum::Value], $check)){
                        $id_data=$param['check'][ResultsType::Second[XPHEnum::Value]];
                        $id = '';
                        foreach ($id_data as $k => $v) {
                            if($k==0){
                                $id="'".$v."'";
                            }else{
                                $id.=",'".$v."'";
                            }
                        }
                        $connar['where'] .=" and db_monograph.id in(".$id.")";
                    }else{
                        $connar['where'].=" and 1<>1";
                    }
                }else{
                    $connar['where'].=" and 1<>1";
                }
            }
            $data = $this->CI->Monograph_model->get_list_full($connar);
            foreach ($data as $k => $v) {
              if(isset($v['is_cooperation'])){
                    $data[$k]['is_cooperation'] = (new CommonWhether())->show($v['is_cooperation']);
                } 
                $data[$k]['publish_time'] = date('Y-m-d', $v['publish_time']);
               if(isset($v['award_year'])){
                     $data[$k]['award_year'] = $v['award_year']?$v['award_year']:'';              
                }else{
                     $data[$k]['award_year'] = '';
                }
                if(isset($param['name']) && $param['name']!=-1){
                    // 判断是否外校
                    $author=array_unique(explode(',', $v['author']));
                    $own_identity=array_search(CommonIdentity::Teacher[XPHEnum::Value], explode(',', $v['identity']));
                    $own_author=array_search($param['name'], explode(',', $v['author']));
                    // 如果该成果人不是排在成果人第一位，则排名都显示为成员
                    $name_arr = explode(",",$param['name']);
                    $name = $name_arr[0];
                    if($name!=$author[0]){
                        $data[$k]['school_rank']='成员';
                        $data[$k]['personal_rank']='成员';
                    }
                }
                unset($data[$k]['identity']);
            }
             if($is_export && !$is_school){

                $table_col         = array('选择','序号', '出版时间', '专著名称', '出版社名称', '出版社级别', '学科门类', '本校排名','个人排名','作者','总字数(千字)','本校撰写字数（千字）','著作类别','资助等级','出版地','ISBN号','是否合作完成','所属单位','业绩分','奖金','备注','业绩（成果）归属年份');
             }else{
                 $table_col = array('选择','序号', '出版时间', '专著名称', '出版社名称', '出版社级别', '学科门类', '本校排名', '个人排名','作者','业绩（成果）归属年份');
             }
           
            $type_name         = ResultsType::Second[XPHEnum::Caption];
            return array('table_name' => $type_name, 'table_col' => $table_col, 'data' => $data);
    }

    //专利模块
   
    public function patent($param, $is_export,$is_school,$check){
          if($is_export && !$is_school){
                  $connar['items'] = "db_patent.id,db_patent.announcement_date,db_patent.name,db_patent.type,db_patent.patent_number,db_patent.school_rank,db_patent.personal_rank,author.author,author.identity,db_patent.apply_date,db_patent.owner,db_patent.range,db_patent.state,db_patent.agent,db_patent.agent_dept,db_patent.is_exclusive,db_patent.dept_name,db_patent.performance_score,db_patent.bonus,db_patent.remark,db_patent.award_year";
             }else{
                   $connar['items'] = "db_patent.id,db_patent.announcement_date,db_patent.name,db_patent.type,db_patent.patent_number,db_patent.school_rank,db_patent.personal_rank,author.author,author.identity,db_patent.award_year";
             }
        
            $connar['where'] = $this->CI->sqlEscape("is_del=?? and status=?? and is_submit_cg=??", array(CommonWhether::Not[XPHEnum::Value], ResultState::Publiced[XPHEnum::Value],CommonWhether::Whether[XPHEnum::Value]));
            $connar['join'][0]=array('(select group_concat(db_author.author_name  ORDER BY id ASC) author,group_concat(db_author.identity  ORDER BY id ASC) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Third[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_patent.id');
            // if (isset($param['name']) && $param['name']!=-1) {
            //     $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author.author) ', array($param['name']));
            // }
             if (isset($param['name']) && $param['name']!=-1) {
                $name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
                $connar['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Third[XPHEnum::Value].') author1','author1.data_id=db_patent.id');
                 $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));
            }
            
            if (isset($param['year']) && $param['year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and DATE_FORMAT(FROM_UNIXTIME(db_patent.announcement_date), "%Y" ) =?? ', array($param['year']));
            }
            if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and db_patent.award_year=?? ', array($param['submit_year']));
            }
            if (isset($param['dept']) && $param['dept'] != -1) {
                $connar['where'] .= $this->CI->sqlEscape(' and db_patent.dept_name=?? ', array($param['dept']));
            }
            $data = $this->CI->Patent_model->get_list_full($connar);
            foreach ($data as $k => $v) {
                $data[$k]['announcement_date'] = date('Y-m-d', $v['announcement_date']);
            }
            if($is_export && !$is_school){
                if(isset($check) && !empty($check)){
                    if(in_array(ResultsType::Third[XPHEnum::Value], $check)){
                        $id_data=$param['check'][ResultsType::Third[XPHEnum::Value]];
                        $id = '';
                        foreach ($id_data as $k => $v) {
                            if($k==0){
                                $id="'".$v."'";
                            }else{
                                $id.=",'".$v."'";
                            }
                        }
                        $connar['where'] .=" and db_patent.id in(".$id.")";
                    }else{
                        $connar['where'].=" and 1<>1";
                    }
                }else{
                    $connar['where'].=" and 1<>1";
                }
            }
            $data = $this->CI->Patent_model->get_list_full($connar);

            foreach ($data as $k => $v) {
                $data[$k]['announcement_date'] = date('Y-m-d', $v['announcement_date']);
                 if(isset($v['award_year'])){
                     $data[$k]['award_year'] = $v['award_year']?$v['award_year']:'';              
                }else{
                     $data[$k]['award_year'] = '';
                }
                $identity_title=array_unique(explode(',', $v['identity']));      
                $author=array_unique(explode(',', $v['author']));  
                if(isset($param['name']) && $param['name']!=-1){
                    // 判断是否外校
                    $author=array_unique(explode(',', $v['author']));
                    $own_identity=array_search(CommonIdentity::Teacher[XPHEnum::Value], explode(',', $v['identity']));
                    $own_author=array_search($param['name'], explode(',', $v['author']));
                    // 如果该成果人不是排在成果人第一位，则排名都显示为成员
                    $name_arr = explode(",",$param['name']);
                    $name = $name_arr[0];
                    if($name!=$author[0]){
                        $data[$k]['school_rank']='成员';
                        $data[$k]['personal_rank']='成员';
                    }
                }  
            }

           foreach ($data as $k2 => $v1) {
             $identity_title=array_unique(explode(',', $v1['identity']));   
              if(count($identity_title)==1){
                 $data[$k2]['identity'] = (new CommonIdentity)->show($identity_title[0]);
               }else{
                     $identity_title_arr = array();
                     foreach ($identity_title as $k1 => $v) {
                        $identity_title_arr[$k1]=(new CommonIdentity)->show($v);
                    }
                    $data[$k2]['identity'] =implode('/', $identity_title_arr);
               }

             if($is_export && !$is_school){
                 $data[$k2]['apply_date'] = date('Y-m-d', $v1['apply_date']);
                $data[$k2]['is_exclusive'] = (new CommonWhether())->show($v1['is_exclusive']);
                $data[$k2]['state'] = (new PatentSystemState())->show($v1['state']);
                }
           }
         //  pri( $data);
            if($is_export && !$is_school){
                $table_col         = array('选择','序号', '授权时间', '专利名称', '专利类型', '专利号', '本校排名','个人排名', '发明人','本校教师/学生','申请日','专利权人','专利范围','专利状态','代理人','代理单位','专利权是否独享', '所属单位','业绩分','奖金','备注','业绩（成果）归属年份');

             }else{
                 $table_col  = array('选择','序号', '授权时间', '专利名称', '专利类型', '专利号', '本校排名','个人排名', '发明人', ' 本校教师/学生','业绩（成果）归属年份');
             }
            $type_name         = ResultsType::Third[XPHEnum::Caption];
            return array('table_name' => $type_name, 'table_col' => $table_col, 'data' => $data);
    }

    //获奖模块
   
    public function awards($param, $is_export,$is_school,$check){
          if($is_export && !$is_school){
                $connar['items'] = "db_awards.id,db_awards.award_time,db_awards.name,db_awards.award_name,db_awards.award_dept,db_awards.award_type,db_awards.award_grade,db_awards.school_rank,db_awards.personal_rank,author.author main_complete,author.identity,db_awards.subject,db_awards.award_year,db_awards.award_session,db_awards.award_level,db_awards.is_cooperation,db_awards.certificate_number,db_awards.dept_name,db_awards.performance_score,db_awards.bonus,db_awards.remark";
             }else{
                $connar['items'] = "db_awards.id,db_awards.award_time,db_awards.name,db_awards.award_name,db_awards.award_dept,db_awards.award_level,db_awards.award_type,db_awards.award_grade,db_awards.school_rank,db_awards.personal_rank,author.author main_complete,author.identity,db_awards.award_year";
             }

            $connar['where'] = $this->CI->sqlEscape("is_del=?? and status=?? and is_submit_cg=??", array(CommonWhether::Not[XPHEnum::Value], ResultState::Publiced[XPHEnum::Value],CommonWhether::Whether[XPHEnum::Value]));
            $connar['join'][0]=array('(select group_concat(db_author.author_name  ORDER BY id ASC) author,group_concat(db_author.identity  ORDER BY id ASC) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Fourth[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_awards.id');
            // if (isset($param['name']) && $param['name']!=-1) {
            //     $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author.author) ', array($param['name']));
            // }
             if (isset($param['name']) && $param['name']!=-1) {
                $name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
                $connar['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Fourth[XPHEnum::Value].') author1','author1.data_id=db_awards.id');
                 $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));

            }
            if (isset($param['year']) && $param['year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and DATE_FORMAT(FROM_UNIXTIME(db_awards.award_time), "%Y" ) =?? ', array($param['year']));
            }
            if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and db_awards.award_year=??  ', array($param['submit_year']));
            }
            if (isset($param['dept'])) {
                $connar['where'] .= $this->CI->sqlEscape(' and db_awards.dept_name=?? ', array($param['dept']));
            }
            if($is_export && !$is_school){
                if(isset($check) && !empty($check)){
                    if(in_array(ResultsType::Fourth[XPHEnum::Value], $check)){
                        $id_data=$param['check'][ResultsType::Fourth[XPHEnum::Value]];
                        $id = '';
                        foreach ($id_data as $k => $v) {
                            if($k==0){
                                $id="'".$v."'";
                            }else{
                                $id.=",'".$v."'";
                            }
                        }
                        $connar['where'] .=" and db_awards.id in(".$id.")";
                    }else{
                        $connar['where'].=" and 1<>1";
                    }
                }else{
                    $connar['where'].=" and 1<>1";
                }
            }
            $data = $this->CI->Awards_model->get_list_full($connar);
            foreach ($data as $k => $v) {
                $data[$k]['award_time'] = $v['award_time'] ? date('Y-m-d', $v['award_time']) : '';
               if(isset($v['award_year'])){
                     $data[$k]['award_year'] = $v['award_year']?$v['award_year']:'';               
                }else{
                     $data[$k]['award_year'] = '';
                }
                if($is_export && !$is_school){
                    $data[$k]['is_cooperation'] = (new CommonWhether())->show($v['is_cooperation']);
                } 
                if(isset($param['name']) && $param['name']!=-1){
                    // 判断是否外校
                    $author=array_unique(explode(',', $v['main_complete']));
                    $own_identity=array_search(CommonIdentity::Teacher[XPHEnum::Value], explode(',', $v['identity']));
                    $own_author=array_search($param['name'], explode(',', $v['main_complete']));
                    // 如果该成果人不是排在成果人第一位，则排名都显示为成员
                   $name_arr = explode(",",$param['name']);
                    $name = $name_arr[0];
                    if($name!=$author[0]){
                        $data[$k]['school_rank']='成员';
                        $data[$k]['personal_rank']='成员';
                    }
                }  
                unset($data[$k]['identity']);
            }

            if($is_export && !$is_school){
                 $table_col  = array('选择','序号', '获奖时间', '成果名称', '奖项名称', '颁奖单位', '奖励类别', '奖项级别', '本校排名','个人排名', '作者','学科门类','业绩（成果）归属年份','奖励届级','奖励等级','是否合作完成','证书号','所属单位','业绩分','奖金','备注');
             }else{
                 $table_col = array('选择','序号', '获奖时间', '成果名称', '奖项名称', '颁奖单位','奖励等级', '奖励类别', '奖项级别', '本校排名','个人排名', '作者','业绩（成果）归属年份');
             }
            $type_name         = ResultsType::Fourth[XPHEnum::Caption];
           
            return array('table_name' => $type_name, 'table_col' => $table_col, 'data' => $data);
    }

    //研究报告、政策建议模块
   
    public function research_report($param, $is_export,$is_school,$check){
         if($is_export && !$is_school){
                $connar['items'] = "db_research_report.id,db_research_report.submit_date,db_research_report.name,db_research_report.type,db_research_report.level,db_research_report.submit_dept,db_research_report.school_rank,db_research_report.personal_rank,author.author,author.identity,db_research_report.words_number,db_research_report.subject,db_research_report.is_cooperation,db_research_report.dept_name,db_research_report.performance_score,db_research_report.bonus,db_research_report.award_year";
             }else{
                $connar['items'] = "db_research_report.id,db_research_report.submit_date,db_research_report.name,db_research_report.type,db_research_report.level,db_research_report.submit_dept,db_research_report.school_rank,db_research_report.personal_rank,author.author,author.identity,db_research_report.award_year";
             }
            

            $connar['where'] = $this->CI->sqlEscape("is_del=?? and status=?? and is_submit_cg=??", array(CommonWhether::Not[XPHEnum::Value], ResultState::Publiced[XPHEnum::Value],CommonWhether::Whether[XPHEnum::Value]));
            $connar['join'][0]=array('(select group_concat(db_author.author_name  ORDER BY id ASC) author,group_concat(db_author.identity  ORDER BY id ASC) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Fifth[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_research_report.id');
            // if (isset($param['name']) && $param['name']!=-1) {
            //     $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author.author) ', array($param['name']));
            // }
             if (isset($param['name']) && $param['name']!=-1) {
                $name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
               $connar['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Fifth[XPHEnum::Value].') author1','author1.data_id=db_research_report.id');
                 $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));

            }
            if (isset($param['year']) && $param['year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and DATE_FORMAT(FROM_UNIXTIME(db_research_report.submit_date), "%Y" ) =?? ', array($param['year']));
            }
            if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and db_research_report.award_year=?? ', array($param['submit_year']));
            }
            if (isset($param['dept'])) {
                $connar['where'] .= $this->CI->sqlEscape(' and db_research_report.dept_name=?? ', array($param['dept']));
            }
            if($is_export && !$is_school){
                if(isset($check) && !empty($check)){
                    if(in_array(ResultsType::Fifth[XPHEnum::Value], $check)){
                        $id_data=$param['check'][ResultsType::Fifth[XPHEnum::Value]];
                        $id = '';
                        foreach ($id_data as $k => $v) {
                            if($k==0){
                                $id="'".$v."'";
                            }else{
                                $id.=",'".$v."'";
                            }
                        }
                        $connar['where'] .=" and db_research_report.id in(".$id.")";
                    }else{
                        $connar['where'].=" and 1<>1";
                    }
                }else{
                    $connar['where'].=" and 1<>1";
                }
            }
            $data = $this->CI->Research_report_model->get_list_full($connar);
            foreach ($data as $k => $v) {
                $data[$k]['submit_date'] =  $v['submit_date'] ? date('Y-m-d',  $v['submit_date']) : '';
                 if(isset($v['award_year'])){
                    $data[$k]['award_year'] = $v['award_year']?$v['award_year']:'';                  
                }else{
                     $data[$k]['award_year'] = '';
                }
                if($is_export && !$is_school){
                 $data[$k]['is_cooperation'] = (new CommonWhether())->show($v['is_cooperation']);
                } 
                if(isset($param['name']) && $param['name']!=-1){
                    // 判断是否外校
                    $author=array_unique(explode(',', $v['author']));
                    $own_identity=array_search(CommonIdentity::Teacher[XPHEnum::Value], explode(',', $v['identity']));
                    $own_author=array_search($param['name'], explode(',', $v['author']));
                    // 如果该成果人不是排在成果人第一位，则排名都显示为成员
                    $name_arr = explode(",",$param['name']);
                    $name = $name_arr[0];
                    if($name!=$author[0]){
                        $data[$k]['school_rank']='成员';
                        $data[$k]['personal_rank']='成员';
                    }
                }
                unset($data[$k]['identity']);
            }

            if($is_export && !$is_school){
                $table_col  = array('选择','序号', '批示或采纳时间', '报告名称', '报告类型', '报告级别', '提交单位', '本校排名','个人排名', '作者','字数（万字)','学科门类','是否合作完成','所属单位','业绩分','奖金','业绩（成果）归属年份');
             }else{
                $table_col = array('选择','序号', '批示或采纳时间', '报告名称', '报告类型', '报告级别', '提交单位', '本校排名','个人排名', '作者','业绩（成果）归属年份');
             }

            $type_name         = ResultsType::Fifth[XPHEnum::Caption];
      
            return array('table_name' => $type_name, 'table_col' => $table_col, 'data' => $data);
    }

    //技术标准模块
   
    public function technical_standard($param, $is_export,$is_school,$check){
        if($is_export && !$is_school){
            $connar['items'] = "db_technical_standard.id,db_technical_standard.publish_time,db_technical_standard.name,db_technical_standard.code,db_technical_standard.publish_dept,db_technical_standard.standard_level,db_technical_standard.school_rank,db_technical_standard.personal_rank,author.author,author.identity,db_technical_standard.dept_name,db_technical_standard.performance_score,db_technical_standard.bonus,db_technical_standard.award_year";
             }else{
                 $connar['items'] = "db_technical_standard.id,db_technical_standard.publish_time,db_technical_standard.name,db_technical_standard.code,db_technical_standard.publish_dept,db_technical_standard.standard_level,db_technical_standard.school_rank,db_technical_standard.personal_rank,author.author,author.identity,db_technical_standard.award_year";
             }          

            $connar['where'] = $this->CI->sqlEscape("is_del=?? and status=?? and is_submit_cg=??", array(CommonWhether::Not[XPHEnum::Value], ResultState::Publiced[XPHEnum::Value],CommonWhether::Whether[XPHEnum::Value]));
            $connar['join'][0]=array('(select group_concat(db_author.author_name  ORDER BY id ASC) author,group_concat(db_author.identity  ORDER BY id ASC) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Sixth[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_technical_standard.id');
            // if (isset($param['name']) && $param['name']!=-1) {
            //     $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author.author) ', array($param['name']));
            // }
             if (isset($param['name']) && $param['name']!=-1) {
                $name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
                $connar['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Sixth[XPHEnum::Value].') author1','author1.data_id=db_technical_standard.id');
                 $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));
            }
            if (isset($param['year']) && $param['year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and DATE_FORMAT(FROM_UNIXTIME(db_technical_standard.publish_time), "%Y" ) =?? ', array($param['year']));
            }
            if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and db_technical_standard.award_year=?? ', array($param['submit_year']));
            }
            if (isset($param['dept'])) {
                $connar['where'] .= $this->CI->sqlEscape(' and db_technical_standard.dept_name=?? ', array($param['dept']));
            }
            if($is_export && !$is_school){
                if(isset($check) && !empty($check)){
                    if(in_array(ResultsType::Sixth[XPHEnum::Value], $check)){
                        $id_data=$param['check'][ResultsType::Sixth[XPHEnum::Value]];
                        $id = '';
                        foreach ($id_data as $k => $v) {
                            if($k==0){
                                $id="'".$v."'";
                            }else{
                                $id.=",'".$v."'";
                            }
                        }
                        $connar['where'] .=" and db_technical_standard.id in(".$id.")";
                    }else{
                        $connar['where'].=" and 1<>1";
                    }
                }else{
                    $connar['where'].=" and 1<>1";
                }
            }
            $data = $this->CI->Technical_standard_model->get_list_full($connar);
            foreach ($data as $k => $v) {
                $data[$k]['publish_time'] = date('Y-m-d', $v['publish_time']);
                 if(isset($v['award_year'])){
                    $data[$k]['award_year'] = $v['award_year']?$v['award_year']:'';                 
                }else{
                     $data[$k]['award_year'] = '';
                }
                if(isset($param['name']) && $param['name']!=-1){
                    // 判断是否外校
                    $author=array_unique(explode(',', $v['author']));
                    $own_identity=array_search(CommonIdentity::Teacher[XPHEnum::Value], explode(',', $v['identity']));
                    $own_author=array_search($param['name'], explode(',', $v['author']));
                    // 如果该成果人不是排在成果人第一位，则排名都显示为成员
                    $name_arr = explode(",",$param['name']);
                    $name = $name_arr[0];
                    if($name!=$author[0]){
                        $data[$k]['school_rank']='成员';
                        $data[$k]['personal_rank']='成员';
                    }
                }
                unset($data[$k]['identity']);
            }

            if($is_export && !$is_school){
                  $table_col         = array('选择','序号', '发布时间', '标准名称', '标准代码', '发布单位', '标准级别', '本校排名', '个人排名','作者','所属单位','业绩分','奖金','业绩（成果）归属年份');
             }else{
                  $table_col         = array('选择','序号', '发布时间', '标准名称', '标准代码', '发布单位', '标准级别', '本校排名', '个人排名', '作者','业绩（成果）归属年份');
             }
            $type_name         = ResultsType::Sixth[XPHEnum::Caption];
          
             return array('table_name' => $type_name, 'table_col' => $table_col, 'data' => $data);
    }

    //纵向课题模块
   
    public function vertical_project($param, $is_export,$is_school,$check){
         if($is_export && !$is_school){
                 $connar['items'] = "db_vertical_project.id,db_vertical_project.project_time,db_vertical_project.name,db_vertical_project.source,db_vertical_project.level,db_vertical_project.funding,db_vertical_project.matching_funding,db_vertical_project.school_rank,db_vertical_project.personal_rank,author.author,author.identity,db_vertical_project.is_end,db_vertical_project.number,db_vertical_project.dept_name,db_vertical_project.performance_score,db_vertical_project.bonus,db_vertical_project.award_year";
             }else{
                 $connar['items'] = "db_vertical_project.id,db_vertical_project.project_time,db_vertical_project.name,db_vertical_project.source,db_vertical_project.level,db_vertical_project.funding,db_vertical_project.matching_funding,db_vertical_project.school_rank,db_vertical_project.personal_rank,author.author,author.identity,is_end,db_vertical_project.award_year";
             }

           

            $connar['where'] = $this->CI->sqlEscape("is_del=?? and status=?? and is_submit_cg=??", array(CommonWhether::Not[XPHEnum::Value], ResultState::Publiced[XPHEnum::Value],CommonWhether::Whether[XPHEnum::Value]));
            $connar['join'][0]=array('(select group_concat(db_author.author_name  ORDER BY id ASC) author,group_concat(db_author.identity  ORDER BY id ASC) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Seventh[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_vertical_project.id');
            // $connar['orderby'] = ' is_end desc';
            // if (isset($param['name']) && $param['name']!=-1) {
            //     $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author.author) ', array($param['name']));
            // }
             if (isset($param['name']) && $param['name']!=-1) {
                $name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
               $connar['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Seventh[XPHEnum::Value].') author1','author1.data_id=db_vertical_project.id');
                 $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));
            }
            if (isset($param['year']) && $param['year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and DATE_FORMAT(FROM_UNIXTIME(db_vertical_project.project_time), "%Y" ) =?? ', array($param['year']));
            }
            if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and db_vertical_project.award_year=?? ', array($param['submit_year']));
            }
            if (isset($param['dept'])) {
                $connar['where'] .= $this->CI->sqlEscape(' and db_vertical_project.dept_name=?? ', array($param['dept']));
            }
            if($is_export && !$is_school){
                if(isset($check) && !empty($check)){
                    if(in_array(ResultsType::Seventh[XPHEnum::Value], $check)){
                        $id_data=$param['check'][ResultsType::Seventh[XPHEnum::Value]];
                        $id = '';
                        foreach ($id_data as $k => $v) {
                            if($k==0){
                                $id="'".$v."'";
                            }else{
                                $id.=",'".$v."'";
                            }
                        }
                        $connar['where'] .=" and db_vertical_project.id in(".$id.")";
                    }else{
                        $connar['where'].=" and 1<>1";
                    }
                }else{
                    $connar['where'].=" and 1<>1";
                }
            }
            $data = $this->CI->Vertical_project_model->get_list_full($connar);

            // echo  $this->CI->db->last_query();

              // pri($data);
               $role=explode(',', getSess()['sub_role_id']);
               array_push($role, getSess()['role_id']);

               // pri($role);

            foreach ($data as $k => $v) {
                $data[$k]['project_time'] = $v['project_time'] ? date('Y-m-d',  $v['project_time']) : '';
                 if(isset($v['award_year'])){
                     $data[$k]['award_year'] = $v['award_year']?$v['award_year']:'';                 
                }else{
                     $data[$k]['award_year'] = '';
                }
                $data[$k]['is_end']=(new CommonWhether)->show($v['is_end']);
                if(isset($param['name']) && $param['name']!=-1){
                    // 判断是否外校
                    $author=array_unique(explode(',', $v['author']));
                    $own_identity=array_search(CommonIdentity::Teacher[XPHEnum::Value], explode(',', $v['identity']));
                    $own_author=array_search($param['name'], explode(',', $v['author']));
                    // 如果该成果人不是排在成果人第一位，则排名都显示为成员
                    $name_arr = explode(",",$param['name']);
                    $name = $name_arr[0];
                    if($name!=$author[0]){
                        $data[$k]['school_rank']='成员';
                         $data[$k]['personal_rank']='成员';
                    }
                }
                unset($data[$k]['identity']);
                
              //当一个课题存在立项或结题两条数据，若登录人为领导则默认只显示结题
                if (in_array(WebRole::SchoolLeader[XPHEnum::Value], $role)){
                    $count_name = $this->CI->Vertical_project_model->get_count(array('name'=>$v['name'],'status'=>ResultState::Publiced[XPHEnum::Value]));
                    $count_end = $this->CI->Vertical_project_model->get_count(array('name'=>$v['name'],'is_end'=>1,'status'=>ResultState::Publiced[XPHEnum::Value]));

                    if($count_name > 1 && $count_end > 0){
                        // pri(111);
                        $count_list = $this->CI->Vertical_project_model->get_list(array('name'=>$v['name'],'is_end'=>0,'status'=>ResultState::Publiced[XPHEnum::Value]));
                        foreach($count_list as $k1=>$v1){
                            if($v1['id'] == $v['id']){
                               unset($data[$k]);
                            }
                        }
                    }
                }      
            }


            // pri($data);

          

            if($is_export && !$is_school){
                 $table_col         = array('选择','序号', '立项时间', '课题名称', '来源', '级别', '到校经费', '配套经费', '本校排名','个人排名', '完成人', '是否结题','课题编号','所属单位','业绩分','奖金','业绩（成果）归属年份');
             }else{
                 $table_col         = array('选择','序号', '立项时间', '课题名称', '来源', '级别', '到校经费', '配套经费', '本校排名','个人排名', '完成人', '是否结题','业绩（成果）归属年份');
             }

            $type_name         = ResultsType::Seventh[XPHEnum::Caption];
           
             return array('table_name' => $type_name, 'table_col' => $table_col, 'data' => $data);
    }

    //横向课题模块
   
    public function horizontal_project($param, $is_export,$is_school,$check){
         if($is_export && !$is_school){
                 $connar['items'] = "db_horizontal_project.id,db_horizontal_project.project_time,db_horizontal_project.name,db_horizontal_project.source,db_horizontal_project.contract_funding,db_horizontal_project.account_funding,db_horizontal_project.personal_rank,author.author,author.identity,db_horizontal_project.is_end,db_horizontal_project.number,db_horizontal_project.dept_name,db_horizontal_project.performance_score,db_horizontal_project.bonus,db_horizontal_project.award_year";
             }else{
                 $connar['items'] = "db_horizontal_project.id,db_horizontal_project.project_time,db_horizontal_project.name,db_horizontal_project.source,db_horizontal_project.contract_funding,db_horizontal_project.account_funding,db_horizontal_project.personal_rank,author.author,author.identity,is_end,db_horizontal_project.award_year";
             }
           

            $connar['where'] = $this->CI->sqlEscape("is_del=?? and status=?? and is_submit_cg=??", array(CommonWhether::Not[XPHEnum::Value], ResultState::Publiced[XPHEnum::Value],CommonWhether::Whether[XPHEnum::Value]));
            $connar['join'][0]=array('(select group_concat(db_author.author_name  ORDER BY id ASC) author,group_concat(db_author.identity  ORDER BY id ASC) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Eighth[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_horizontal_project.id');
            // if (isset($param['name']) && $param['name']!=-1) {
            //     $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author.author) ', array($param['name']));
            // }
             if (isset($param['name']) && $param['name']!=-1) {
                $name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
                  $connar['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Eighth[XPHEnum::Value].') author1','author1.data_id=db_horizontal_project.id');
                 $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));
            }
            if (isset($param['year']) && $param['year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and DATE_FORMAT(FROM_UNIXTIME(db_horizontal_project.project_time), "%Y" ) =?? ', array($param['year']));
            }
            if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and db_horizontal_project.award_year=??  ', array($param['submit_year']));
            }
            if (isset($param['dept'])) {
                $connar['where'] .= $this->CI->sqlEscape(' and db_horizontal_project.dept_name=?? ', array($param['dept']));
            }
            if($is_export && !$is_school){
                if(isset($check) && !empty($check)){
                    if(in_array(ResultsType::Eighth[XPHEnum::Value], $check)){
                        $id_data=$param['check'][ResultsType::Eighth[XPHEnum::Value]];
                        $id = '';
                        foreach ($id_data as $k => $v) {
                            if($k==0){
                                $id="'".$v."'";
                            }else{
                                $id.=",'".$v."'";
                            }
                        }
                        $connar['where'] .=" and db_horizontal_project.id in(".$id.")";
                    }else{
                        $connar['where'].=" and 1<>1";
                    }
                }else{
                    $connar['where'].=" and 1<>1";
                }
            }
            $data = $this->CI->Horizontal_project_model->get_list_full($connar);

              $role=explode(',', getSess()['sub_role_id']);
               array_push($role, getSess()['role_id']);

            foreach ($data as $k => $v) {
                $data[$k]['project_time'] = $v['project_time'] ? date('Y-m-d',  $v['project_time']) : '';               
                 if(isset($v['award_year'])){
                     $data[$k]['award_year'] = $v['award_year']?$v['award_year']:'';               
                }else{
                     $data[$k]['award_year'] = '';
                }                
                $data[$k]['is_end']=(new CommonWhether)->show($v['is_end']);
   
                if(isset($param['name']) && $param['name']!=-1){
                    // 判断是否外校
                    $author=array_unique(explode(',', $v['author']));
                    $own_identity=array_search(CommonIdentity::Teacher[XPHEnum::Value], explode(',', $v['identity']));
                    $own_author=array_search($param['name'], explode(',', $v['author']));
                    // 如果该成果人不是排在成果人第一位，则排名都显示为成员
                    $name_arr = explode(",",$param['name']);
                    $name = $name_arr[0];
                    if($name!=$author[0]){
                        $data[$k]['personal_rank']='成员';
                    }
                }

                unset($data[$k]['identity']);

               //当一个课题存在立项或结题两条数据，若登录人为领导则默认只显示结题
                if (in_array(WebRole::SchoolLeader[XPHEnum::Value], $role)){
                    $count_name = $this->CI->Horizontal_project_model->get_count(array('name'=>$v['name'],'status'=>ResultState::Publiced[XPHEnum::Value]));
                    $count_end = $this->CI->Horizontal_project_model->get_count(array('name'=>$v['name'],'is_end'=>1,'status'=>ResultState::Publiced[XPHEnum::Value]));

                    if($count_name > 1 && $count_end > 0){
                        // pri(111);
                        $count_list = $this->CI->Horizontal_project_model->get_list(array('name'=>$v['name'],'is_end'=>0,'status'=>ResultState::Publiced[XPHEnum::Value]));
                        foreach($count_list as $k1=>$v1){
                            if($v1['id'] == $v['id']){
                               unset($data[$k]);
                            }
                        }
                    }
                }
            }
           
            if($is_export && !$is_school){
                  $table_col         = array('选择','序号', '立项时间', '课题名称', '来源', '合同经费', '到校经费','个人排名', '完成人', '是否结题','课题编号','所属单位','业绩分','奖金','业绩（成果）归属年份');
             }else{
                  $table_col         = array('选择','序号', '立项时间', '课题名称', '来源', '合同经费', '到校经费','个人排名', '完成人', '是否结题','业绩（成果）归属年份');
             }

            $type_name         = ResultsType::Eighth[XPHEnum::Caption];
          
            return array('table_name' => $type_name, 'table_col' => $table_col, 'data' => $data);
    }

    //科技转化情况模块
   
    public function science_conversion($param, $is_export,$is_school,$check){
        if($is_export && !$is_school){
                  $connar['items'] = "db_science_conversion.id,db_science_conversion.time,db_science_conversion.name,db_science_conversion.type,db_science_conversion.form,db_science_conversion.science_name,db_science_conversion.personal_rank,author.author,author.identity,db_science_conversion.contract_funding,db_science_conversion.account_funding,db_science_conversion.dept_name,db_science_conversion.performance_score,db_science_conversion.bonus,db_science_conversion.remark,db_science_conversion.award_year";
             }else{
                  $connar['items'] = "db_science_conversion.id,db_science_conversion.time,db_science_conversion.name,db_science_conversion.type,db_science_conversion.form,db_science_conversion.science_name,db_science_conversion.personal_rank,author.author,author.identity,db_science_conversion.contract_funding,db_science_conversion.account_funding,db_science_conversion.award_year";
             }   

            $connar['where'] = $this->CI->sqlEscape("is_del=?? and status=?? and is_submit_cg=??", array(CommonWhether::Not[XPHEnum::Value], ResultState::Publiced[XPHEnum::Value],CommonWhether::Whether[XPHEnum::Value]));

            $connar['join'][0]=array('(select group_concat(db_author.author_name  ORDER BY id ASC) author,group_concat(db_author.identity  ORDER BY id ASC) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Ninth[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_science_conversion.id');
            // if (isset($param['name']) && $param['name']!=-1) {
            //     $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author.author) ', array($param['name']));
            // }
             if (isset($param['name']) && $param['name']!=-1) {
                $name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
                $connar['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Ninth[XPHEnum::Value].') author1','author1.data_id=db_science_conversion.id');
                 $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));
            }
            if (isset($param['year']) && $param['year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and DATE_FORMAT(FROM_UNIXTIME(db_science_conversion.time), "%Y" ) =?? ', array($param['year']));
            }
            if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and db_science_conversion.award_year=?? ', array($param['submit_year']));
            }
            if (isset($param['dept'])) {
                $connar['where'] .= $this->CI->sqlEscape(' and db_science_conversion.dept_name=?? ', array($param['dept']));
            }
            if($is_export && !$is_school){
                if(isset($check) && !empty($check)){
                    if(in_array(ResultsType::Ninth[XPHEnum::Value], $check)){
                        $id_data=$param['check'][ResultsType::Ninth[XPHEnum::Value]];
                        $id = '';
                        foreach ($id_data as $k => $v) {
                            if($k==0){
                                $id="'".$v."'";
                            }else{
                                $id.=",'".$v."'";
                            }
                        }
                        $connar['where'] .=" and db_science_conversion.id in(".$id.")";
                    }else{
                        $connar['where'].=" and 1<>1";
                    }
                }else{
                    $connar['where'].=" and 1<>1";
                }
            }
            $data = $this->CI->Science_conversion_model->get_list_full($connar);
            foreach ($data as $k => $v) {
                $data[$k]['time'] =$v['time'] ? date('Y-m-d',  $v['time']) : '';
                if(isset($v['award_year'])){
                     $data[$k]['award_year'] = $v['award_year']?$v['award_year']:'';             
                }else{
                     $data[$k]['award_year'] = '';
                }
                if(isset($param['name']) && $param['name']!=-1){
                    // 判断是否外校
                    $author=array_unique(explode(',', $v['author']));
                    $own_identity=array_search(CommonIdentity::Teacher[XPHEnum::Value], explode(',', $v['identity']));
                    $own_author=array_search($param['name'], explode(',', $v['author']));
                    // 如果该成果人不是排在成果人第一位，则排名都显示为成员
                    $name_arr = explode(",",$param['name']);
                    $name = $name_arr[0];
                    if($name!=$author[0]){
                        $data[$k]['personal_rank']='成员';
                    }
                }
                unset($data[$k]['identity']);
            }
            $type_name         = ResultsType::Ninth[XPHEnum::Caption];
           if($is_export && !$is_school){
                $table_col         = array('选择','序号', '转化合同签订时间', '转化成果名称', '成果类型', '转化形式', '转化单位','个人排名', '完成人', '合同金额', '到账金额','所属单位','业绩分','奖金','备注','业绩（成果）归属年份');
             }else{
                $table_col         = array('选择','序号', '转化合同签订时间', '转化成果名称', '成果类型', '转化形式', '转化单位','个人排名', '完成人', '合同金额', '到账金额','业绩（成果）归属年份');
             }

            
            return array('table_name' => $type_name, 'table_col' => $table_col, 'data' => $data);
    }

    //举办、参加学术交流会、学会年会模块
   
    public function communication($param, $is_export,$is_school,$check){
          if($is_export && !$is_school){
                $connar1['items'] = "id,time,name,organizer_dept,join_type,type,participants,adress,person_time,paper_num,dept_name,performance_score,award_year";
             }else{
                $connar1['items'] = "id,time,name,organizer_dept,join_type,participants,award_year";
             }
            

            $connar1['where'] = $this->CI->sqlEscape("is_del=?? and status=?? and is_submit_cg=??", array(CommonWhether::Not[XPHEnum::Value], ResultState::Publiced[XPHEnum::Value],CommonWhether::Whether[XPHEnum::Value]));
            $connar1['join']=array('(select group_concat(db_author.author_name  ORDER BY id ASC) author,group_concat(db_author.identity  ORDER BY id ASC) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Tenth[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_communication.id');
            // if (isset($param['name']) && $param['name']!=-1) {
            //     $connar1['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author.author) ', array($param['name']));
            // }
             if (isset($param['name']) && $param['name']!=-1) {
                 // 没有找到成果人字段
                 $connar1['where'] .= $this->CI->sqlEscape(' and 1<>?? ', array(1));
                // $name_arr = explode(",",$param['name']);
                // $name = $name_arr[0];
                // $identity = $name_arr[1];
                //  $connar1['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author.author) and find_in_set(??,author.identity) ', array($name,$identity));
            }
            if (isset($param['year']) && $param['year'] != '') {
                $connar1['where'] .= $this->CI->sqlEscape(' and DATE_FORMAT(FROM_UNIXTIME(time), "%Y" ) =?? ', array($param['year']));
            }
            if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $connar1['where'] .= $this->CI->sqlEscape(' and award_year=?? ', array($param['submit_year']));
            }
            if (isset($param['dept'])) {
                $connar1['where'] .= $this->CI->sqlEscape(' and dept_name=?? ', array($param['dept']));
            }
            if($is_export && !$is_school){
                if(isset($check) && !empty($check)){
                    if(in_array(ResultsType::Tenth[XPHEnum::Value], $check)){
                        $id_data=$param['check'][ResultsType::Tenth[XPHEnum::Value]];
                        $id = '';
                        foreach ($id_data as $k => $v) {
                            if($k==0){
                                $id="'".$v."'";
                            }else{
                                $id.=",'".$v."'";
                            }
                        }
                        $connar1['where'] .=" and id in(".$id.")";
                    }else{
                        $connar1['where'].=" and 1<>1";
                    }
                }else{
                    $connar1['where'].=" and 1<>1";
                }
            }
            $data = $this->CI->Communication_model->get_list_full($connar1);
            foreach ($data as $k => $v) {
                $data[$k]['time'] = date('Y-m-d', $v['time']);
                if(isset($v['award_year'])){
                     $data[$k]['award_year'] = $v['award_year']?$v['award_year']:'';                
                }else{
                     $data[$k]['award_year'] = '';
                }
            }
            $type_name         = ResultsType::Tenth[XPHEnum::Caption];
            if($is_export && !$is_school){
                 $table_col         = array('选择','序号', '参加时间', '活动名称', '主办单位', '参加形式', '类别', '参加人','地点','参加人次','提交论文篇数','所属单位','业绩分','业绩（成果）归属年份');
             }else{
                 $table_col         = array('选择','序号', '参加时间', '活动名称', '主办单位', '参加形式', '参加人','业绩（成果）归属年份');
             }
           
            return array('table_name' => $type_name, 'table_col' => $table_col, 'data' => $data);
    }

    //学术报告模块
   
    public function academic_report($param, $is_export,$is_school,$check){
         if($is_export && !$is_school){
                $connar2['items'] = "id,time,conference,name,expert,expert_dept,adress,dept_name,participants_count,performance_score";
             }else{
                $connar2['items'] = "id,time,name,expert,expert_dept,adress,participants_count,award_year";
             }
            

            $connar2['where'] = $this->CI->sqlEscape("is_del=?? and status=?? and is_submit_cg=??", array(CommonWhether::Not[XPHEnum::Value], ResultState::Publiced[XPHEnum::Value],CommonWhether::Whether[XPHEnum::Value]));
            
            if (isset($param['name']) && $param['name']!=-1) {
                   $connar2['where'] .= $this->CI->sqlEscape(' and 1<>?? ', array(1));
                //  $name_arr = explode(",",$param['name']);
                // $name = $name_arr[0];
                // $connar2['where'] .= $this->CI->sqlEscape(' and expert =??', array($name));
            }
        
            if (isset($param['year']) && $param['year'] != '') {
                $connar2['where'] .= $this->CI->sqlEscape(' and DATE_FORMAT(FROM_UNIXTIME(time), "%Y" ) =?? ', array($param['year']));
            }
            if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $connar2['where'] .= $this->CI->sqlEscape(' and award_year=?? ', array($param['submit_year']));
            }
            if (isset($param['dept'])) {
                $connar2['where'] .= $this->CI->sqlEscape(' and dept_name=?? ', array($param['dept']));
            }
            if($is_export && !$is_school){
                if(isset($check) && !empty($check)){
                    if(in_array(ResultsType::Eleventh[XPHEnum::Value], $check)){
                        $id_data=$param['check'][ResultsType::Eleventh[XPHEnum::Value]];
                        $id = '';
                        foreach ($id_data as $k => $v) {
                            if($k==0){
                                $id="'".$v."'";
                            }else{
                                $id.=",'".$v."'";
                            }
                        }
                        $connar2['where'] .=" and id in(".$id.")";
                    }else{
                        $connar2['where'].=" and 1<>1";
                    }
                }else{
                    $connar2['where'].=" and 1<>1";
                }
            }
            $data = $this->CI->Academic_report_model->get_list_full($connar2);
            foreach ($data as $k => $v) {
                $data[$k]['time'] = $v['time'] ? date('Y-m-d',  $v['time']) : '';    
               if(isset($v['award_year'])){
                     $data[$k]['award_year'] = $v['award_year']?$v['award_year']:'';             
                }else{
                     $data[$k]['award_year'] = '';
                }
            }
            $type_name         = ResultsType::Eleventh[XPHEnum::Caption];
            if($is_export && !$is_school){
                 $table_col         = array('选择','序号',  '举办日期','学术会议', '学术报告题目', '校外被邀专家姓名', '专家单位', '地点','所属单位','参加人次','业绩分','业绩（成果）归属年份');
             }else{
                 $table_col         = array('选择','序号', '举办日期', '学术报告题目', '校外被邀专家姓名', '专家单位', '地点','参加人次','业绩（成果）归属年份');
             }
           
            return array('table_name' => $type_name, 'table_col' => $table_col, 'data' => $data);
    }

    //学术兼职情况模块
   
    public function academia_job($param, $is_export,$is_school,$check){
          if($is_export && !$is_school){
                $connar['items'] = "db_academia_job.id,db_academia_job.academia_start,db_academia_job.academia_end,author.author,db_academia_job.dept,db_academia_job.post,db_academia_job.level,db_academia_job.effect,db_academia_job.dept_name,db_academia_job.performance_score,db_academia_job.award_year";
             }else{
                 $connar['items'] = "db_academia_job.id,db_academia_job.academia_start,db_academia_job.academia_end,author.author,db_academia_job.dept,db_academia_job.post,db_academia_job.level,db_academia_job.effect,db_academia_job.award_year";
             }         

            $connar['where'] = $this->CI->sqlEscape("is_del=?? and status=?? and is_submit_cg=??", array(CommonWhether::Not[XPHEnum::Value], ResultState::Publiced[XPHEnum::Value],CommonWhether::Whether[XPHEnum::Value]));
            $connar['join'][0]=array('(select group_concat(db_author.author_name ORDER BY id ASC) author,group_concat(db_author.identity  ORDER BY id ASC) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Twelfth[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_academia_job.id');
            // if (isset($param['name']) && $param['name']!=-1) {
            //     $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author.author) ', array($param['name']));
            // }
             if (isset($param['name']) && $param['name']!=-1) {
                $name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
                $connar['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Twelfth[XPHEnum::Value].') author1','author1.data_id=db_academia_job.id');
                 $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));
            }
            if (isset($param['year']) && $param['year'] != '') {
                $connar['where'].=$this->CI->sqlEscape(' and (db_academia_job.academia_start<=?? and  db_academia_job.academia_end>=??) ',array($param['year'],$param['year']));
                // 没有兼职时间字段
                $connar['where'] .= " and 1<>1";
            }
            if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and db_academia_job.award_year=?? ', array($param['submit_year']));
            }
            if (isset($param['dept'])) {
                $connar['where'] .= $this->CI->sqlEscape(' and db_academia_job.dept_name=?? ', array($param['dept']));
            }
            if($is_export && !$is_school){
                if(isset($check) && !empty($check)){
                    if(in_array(ResultsType::Twelfth[XPHEnum::Value], $check)){
                        $id_data=$param['check'][ResultsType::Twelfth[XPHEnum::Value]];
                        $id = '';
                        foreach ($id_data as $k => $v) {
                            if($k==0){
                                $id="'".$v."'";
                            }else{
                                $id.=",'".$v."'";
                            }
                        }
                        $connar['where'] .=" and db_academia_job.id in(".$id.")";
                    }else{
                        $connar['where'].=" and 1<>1";
                    }
                }else{
                    $connar['where'].=" and 1<>1";
                }
            }
            $data               = $this->CI->Academia_job_model->get_list_full($connar);
             foreach ($data as $k => $v) {
                if(isset($v['award_year'])){
                     $data[$k]['award_year'] = $v['award_year']?$v['award_year']:'';                 
                }else{
                     $data[$k]['award_year'] = '';
                }
                $data[$k]['academia_start']=date('Y-m-d',$v['academia_start']).'至'.date('Y-m-d',$v['academia_end']);
                unset($data[$k]['academia_end']);
            }

            $type_name          = ResultsType::Twelfth[XPHEnum::Caption];
           
            if($is_export && !$is_school){
                 $table_col  = array('选择','序号', '兼职时间', '兼职人', '兼职机构', '兼职职务', '机构级别', '本校作用','所属单位','业绩分','业绩（成果）归属年份');
             }else{
                 $table_col          = array('选择','序号', '兼职时间', '兼职人', '兼职机构', '兼职职务', '机构级别', '本校作用','业绩（成果）归属年份');
             }
            return array('table_name' => $type_name, 'table_col' => $table_col, 'data' => $data);
    } 

    //学科平台模块
   
   public function subject_platform($param, $is_export,$is_school,$check){
         if($is_export && !$is_school){
                  $connar['items'] = "db_subject_platform.id,db_subject_platform.receive_time,db_subject_platform.name,db_subject_platform.platform_level,db_subject_platform.platform_type,author.author,author.identity,db_subject_platform.school_rank,db_subject_platform.dept_name,db_subject_platform.cooperation_name,db_subject_platform.funding,db_subject_platform.performance_score,db_subject_platform.bonus,db_subject_platform.award_year";
             }else{
                 $connar['items'] = "db_subject_platform.id,db_subject_platform.receive_time,db_subject_platform.name,db_subject_platform.platform_level,db_subject_platform.platform_type,author.author,author.identity,db_subject_platform.school_rank,db_subject_platform.dept_name,db_subject_platform.cooperation_name,db_subject_platform.funding,db_subject_platform.award_year";
             }        

            $connar['where'] = $this->CI->sqlEscape("is_del=?? and status=?? and is_submit_cg=??", array(CommonWhether::Not[XPHEnum::Value], ResultState::Publiced[XPHEnum::Value],CommonWhether::Whether[XPHEnum::Value]));
            $connar['join'][0]=array('(select group_concat(db_author.author_name  ORDER BY id ASC) author,group_concat(db_author.identity) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Thirteen[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_subject_platform.id');
            // if (isset($param['name']) && $param['name']!=-1) {
            //     $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author.author) ', array($param['name']));
            // }
             if (isset($param['name']) && $param['name']!=-1) {
                $name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
                $connar['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Thirteen[XPHEnum::Value].') author1','author1.data_id=db_subject_platform.id');
                $connar['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));
            }
            if (isset($param['year']) && $param['year'] != '') {
                // $connar['where'].=$this->CI->sqlEscape(' and DATE_FORMAT(FROM_UNIXTIME(time), "%Y" ) =?? ',array($param['year']));
                // 没有兼职时间字段
                $connar['where'] .= " and 1<>1";
            }
            if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $connar['where'] .= $this->CI->sqlEscape(' and db_subject_platform.award_year=?? ', array($param['submit_year']));
            }
            if (isset($param['dept'])) {
                $connar['where'] .= $this->CI->sqlEscape(' and db_subject_platform.dept_name=?? ', array($param['dept']));
            }
            if($is_export && !$is_school){
                if(isset($check) && !empty($check)){
                    if(in_array(ResultsType::Thirteen[XPHEnum::Value], $check)){
                        $id_data=$param['check'][ResultsType::Thirteen[XPHEnum::Value]];
                        $id = '';
                        foreach ($id_data as $k => $v) {
                            if($k==0){
                                $id="'".$v."'";
                            }else{
                                $id.=",'".$v."'";
                            }
                        }
                        $connar['where'] .=" and db_subject_platform.id in(".$id.")";
                    }else{
                        $connar['where'].=" and 1<>1";
                    }
                }else{
                    $connar['where'].=" and 1<>1";
                }
            }
            $data               = $this->CI->Subject_platform_model->get_list_full($connar);
            $type_name          = ResultsType::Thirteen[XPHEnum::Caption];
            foreach ($data as $k => $v) {          
                $data[$k]['receive_time'] = $v['receive_time'] ? date('Y-m-d', $v['receive_time']) :'';
                if(isset($v['award_year'])){
                    $data[$k]['award_year'] = $v['award_year']?$v['award_year']:'';            
                }else{
                     $data[$k]['award_year'] = '';
                }
                if(isset($param['name']) && $param['name']!=-1){
                    // 判断是否外校
                    $author=array_unique(explode(',', $v['author']));
                    $own_identity=array_search(CommonIdentity::Teacher[XPHEnum::Value], explode(',', $v['identity']));
                    $own_author=array_search($param['name'], explode(',', $v['author']));
                    // 如果该成果人不是排在成果人第一位，则排名都显示为成员
                    $name_arr = explode(",",$param['name']);
                    $name = $name_arr[0];
                    if($name!=$author[0]){
                        $data[$k]['school_rank']='成员';
                    }
                }
                unset($data[$k]['identity']);
            }

              // pri($data);

            if($is_export && !$is_school){
                 $table_col = array('选择','序号','获得时间', '平台名称', '平台级别', '平台类别', '负责人', '学校排名','所属单位','合作单位','到校经费(万元)','业绩分','奖金','业绩（成果）归属年份');
             }else{
                 $table_col = array('选择','序号','获得时间', '平台名称', '平台级别', '平台类别', '负责人', '学校排名','所属单位','合作单位','到校经费(万元)','业绩（成果）归属年份');
             }
           
            return array('table_name' => $type_name, 'table_col' => $table_col, 'data' => $data);
    }
    

}